package com.zs.games.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zs.games.resultTool.CimResponse;
import com.zs.games.entity.GameInfo;
import com.zs.games.param.IdParam;
import com.zs.games.param.LiveParam;
import com.zs.games.param.PageQuery;
import com.zs.games.param.UserCommentGameParam;
import com.zs.games.service.GameInfoService;
import com.zs.games.vo.GameInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/game")
@Api(tags = "推荐游戏管理")
public class GameInfoController {

    @Autowired
    private GameInfoService gameInfoService;

    @GetMapping("/pageList")
    @ApiOperation("分页游戏列表")
    public CimResponse<IPage<GameInfoVo>> getPageList(PageQuery param) {
        return CimResponse.okData(gameInfoService.getPageList(param));
    }

    @GetMapping("/info")
    @ApiOperation("游戏详情")
    public CimResponse<GameInfoVo> getGameInfoById(@Validated IdParam param) {
        return CimResponse.okData(gameInfoService.getGameInfoById(param.getId()));
    }

    @PostMapping("/add")
    @ApiOperation("新增游戏推荐")
    public CimResponse<Boolean> addGameInfo(@RequestBody GameInfo gameInfo) {
        return CimResponse.okData(gameInfoService.addGameInfo(gameInfo));
    }

    @PostMapping("/update")
    @ApiOperation("修改游戏推荐")
    public CimResponse<Boolean> updateGameInfo(@RequestBody GameInfo gameInfo) {
        return CimResponse.okData(gameInfoService.updateGameInfo(gameInfo));
    }
    @PostMapping("/delete")
    @ApiOperation("删除游戏推荐")
    public CimResponse<Boolean> delete(@RequestBody IdParam param) {
        return CimResponse.okData(gameInfoService.deleteGameInfo(param.getId()));
    }

    @PostMapping("/live")
    @ApiOperation("喜欢/不喜欢")
    public CimResponse<Boolean> live(@RequestBody @Validated LiveParam param) {
        return CimResponse.okData(gameInfoService.liveGameInfo(param.getId(), param.getLiveStatus()));
    }
    @PostMapping("/comment")
    @ApiOperation("评论游戏")
    public CimResponse<Boolean> comment(@RequestBody UserCommentGameParam param) {
        return CimResponse.okData(gameInfoService.commentGame(param));
    }
    @PostMapping("/delComment")
    @ApiOperation("删除游戏评论")
    public CimResponse<Boolean> delComment(@RequestBody IdParam param) {
        return CimResponse.okData(gameInfoService.deleteGameComment(param.getId()));
    }

}
